package com.thiswhyme.sentinel.server1.instance2.controller;

import com.thiswhyme.common.expection.BusinessException;
import com.thiswhyme.common.response.ResponseVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by thiswhyme on 2020/9/3.
 */
@RestController
@RequestMapping("/user1/")
public class UserController {

    public static final Logger log = LoggerFactory.getLogger(UserController.class);

    @GetMapping("user-name")
    public ResponseVo<String> queryUserName(@RequestParam Integer userId) throws InterruptedException {
        if(userId == 0) {
            throw new BusinessException("用户ID错误");
        } else if (userId == 1) {
            Thread.sleep(500);
        } else if (userId == 2) {
            Thread.sleep(1000);
        }
        return ResponseVo.success(userId + "sentinel-test");
    }

    @GetMapping("user-name2")
    public ResponseVo<String> queryUserName2(@RequestParam Integer userId) throws InterruptedException {
        log.info("===》user-name2收到请求");
        if(userId == 8) {
            Thread.sleep(500);
        }
        return ResponseVo.success(userId + "sentinel-test2");
    }

    @GetMapping("user-name3")
    public ResponseVo<String> queryUserName3(@RequestParam Integer userId) throws InterruptedException {
        if(userId == 9) {
            Thread.sleep(1501);
        }
        return ResponseVo.success(userId + "sentinel-test3");
    }
}
